<?php if(!defined('BASEPATH')) exit("Sorry, what you're looking not found.");
class C_rekap extends Nvl_Controller{
    function __construct(){
        parent::__construct();
        session_start();
		$this->__checkSession();
        $this->load->model('m_rekap');
    }

    function index(){
        $this->load->view('pages/v_rekap');
    }
	
	function export_rekap(){
		$params = json_decode($this->input->post("params"));
		extract(get_object_vars($params));
		extract(get_object_vars($form_data));
		
		$filename = 'rekap_prestasi'. $_SESSION[SESSION_USERID];
		$title = 'Rekap Prestasi Periode '. $this->__getIndonesiaDate($rekap_tanggal, TRUE) .' s/d '. $this->__getIndonesiaDate($rekap_tanggal_akhir, TRUE);
		$data['params'] = $params;
		$data['type'] = $type;
		$data['title'] = $title;
		
		if($rekap_jenis == 'Detail'){
			$records = $this->m_rekap->export_rekap_detail($form_data);
			$data['records'] = $records;
			$print_view=$this->load->view("pages/p_rekap_detail.php",$data,TRUE);
		}else if($rekap_jenis == 'Rekap'){
			if($_SESSION[SESSION_SCHOOLID] != 0){
				$records = $this->m_rekap->export_rekap($form_data, 'siswa_kelas');
				$data['header'] = 'Kelas';
			}else{
				$records = $this->m_rekap->export_rekap($form_data, 'sekolah_nama');
				$data['header'] = 'Sekolah';
			}
			$data['records'] = $records;
			$print_view=$this->load->view("pages/p_rekap.php",$data,TRUE);
		}
		if($type == 'print'){
			$print_file=fopen("temp/". $filename .".html","w+");
		}else{
			$print_file=fopen("temp/". $filename .".xls","w+");
		}
		fwrite($print_file, $print_view);
		echo $filename;
	}
	
	function get_list_sekolah(){
		$pagenum = $this->input->numeric('pagenum', 'get');
        $pagesize = $this->input->numeric('pagesize', 'get');
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;
		$search_text = $this->input->get('search_text');
		$result = $this->m_rekap->get_list_sekolah($start, $end, $search_text);
		echo $result;
	}
}